#include    "keyboradinputmanager.h"

#include    "../../common.h"
#include    <string>

KeyBoardInputManager* KeyBoardInputManager::m_instance = 0;

KeyBoardInputManager::KeyBoardInputManager()
{
    memset(m_vkeyDown,false,sizeof(m_vkeyDown[0])*(WIN_VKEY_NUMBER + 1));
    memset(m_fncDown,0,sizeof(m_fncDown[0])*(WIN_VKEY_NUMBER + 1));
    memset(m_fncUp,0,sizeof(m_fncUp[0])*(WIN_VKEY_NUMBER + 1));
}

KeyBoardInputManager::~KeyBoardInputManager()
{

}

void KeyBoardInputManager::keyDown(DWORD key,DWORD lParam)
{
    m_vkeyDown[key] = true;

    if(m_fncDown[key] == 0)
    {
        return;
    }

    m_fncDown[key](lParam);
}

void KeyBoardInputManager::keyUp(DWORD key,DWORD lParam)
{
    m_vkeyDown[key] = false;

    if(m_fncUp[key] == 0)
    {
        return;
    }

    m_fncUp[key](lParam);
}

KeyBoardInputManager* KeyBoardInputManager::getInstance()
{
    return m_instance;
}

void KeyBoardInputManager::createInstance()
{
    if(m_instance)
    {
        return;
    }

    m_instance = new KeyBoardInputManager();
}

void KeyBoardInputManager::releaseInstance()
{
    SAFE_DELETE_OBJ(m_instance);
}
